namespace GameKit.Core.Context
{
    public static class GlobalContext
    {
        private static readonly SystemContext Context = new("GlobalContext");

        public static void Register<T>(T instance)
        {
            Context.Register(instance);
        }

        public static void Register(string tag, object instance)
        {
            Context.Register(tag, instance);
        }

        public static void Unregister<T>()
        {
            Context.Unregister<T>();
        }

        public static void Unregister(string tag)
        {
            Context.Unregister(tag);
        }

        public static T Get<T>()
        {
            return Context.Get<T>();
        }

        public static bool TryGet<T>(out T instance)
        {
            return Context.TryGet(out instance);
        }

        public static T Get<T>(string tag)
        {
            return Context.Get<T>(tag);
        }

        public static bool TryGet<T>(string tag, out T value)
        {
            return Context.TryGet(tag, out value);
        }

        public static T AddSystem<T>() where T : ISystem
        {
            return Context.AddSystem<T>();
        }

        public static T AddSystem<T>(T system) where T : ISystem
        {
            system.Context = Context;
            return Context.AddSystem(system);
        }

        public static T GetSystem<T>() where T : ISystem
        {
            return Context.GetSystem<T>();
        }

        public static void OnUpdate(float deltaTime)
        {
            Context.OnUpdate(deltaTime);
        }

        public static void Dispose()
        {
            Context.Dispose();
        }
    }
}